package com.cskaoyan.controller.backStage;

import com.cskaoyan.model.Brand;
import com.cskaoyan.model.bo.BrandListBO;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.model.vo.BrandDataVO;
import com.cskaoyan.service.BrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：王李轶群
 * @description：商场管理品牌制造商模块
 * @date ：5/5/22 8:44 PM
 */
@RestController
@RequestMapping("admin/brand")
public class BrandController {
    @Autowired
    BrandService brandService;

    /**
     * 获取所有品牌制造商列表
     * @param brandListBO
     * @return
     */
    @RequiresPermissions("admin:brand:list")
    @RequestMapping("list")
    public BaseRespVO<BrandDataVO> brandList(BrandListBO brandListBO){
        BaseRespVO<BrandDataVO> brandList = brandService.getBrandList(brandListBO);
        return brandList;
    }

    /**
     * 新建品牌制造商
     * @param brand
     * @return
     */
    @RequiresPermissions("admin:brand:create")
    @RequestMapping("create")
    public BaseRespVO<Brand> brandCreate(@RequestBody Brand brand){
        BaseRespVO<Brand> brandBaseRespVO = brandService.createBrand(brand);
        return brandBaseRespVO;
    }

    /**
     * 删除品牌制造商
     * @param brand
     * @return
     */
    @RequiresPermissions("admin:brand:delete")
    @RequestMapping("delete")
    public BaseRespVO brandDelete(@RequestBody Brand brand){
        brandService.deleteBrand(brand);
        BaseRespVO baseRespVO = new BaseRespVO();
        baseRespVO.setErrmsg("成功");
        baseRespVO.setErrno(0);
        return baseRespVO;
    }

    /**
     * 更新品牌制造商
     * @param brand
     * @return
     */
    @RequiresPermissions("admin:brand:update")
    @RequestMapping("update")
    public BaseRespVO<Brand> brandUpdate(@RequestBody Brand brand){
        BaseRespVO<Brand> brandBaseRespVO = brandService.updateBrand(brand);
        return brandBaseRespVO;
    }

}
